class PeasonalDetail {
    constructor(divId, acc) {
        this.divId = divId;
        this.acc = acc;
        this.details = ['aid', 'sname', 'ssex', 'sage', 'sumCredit'];
    }

    start() {
        let load = this;
        this.render();
        $(load.divId).show().siblings().hide();

    }

    render() {
        let load = this;
        let acc = load.acc;
        console.log("peasonalDetails--------------------");
        for (let i = 0; i < load.details.length; i++) {
            let val = this.details[i];
            if (val == 'ssex') {
                console.log('.radio-ssex input[value=' + acc[val] + ']');
                // console.log( $("#"+load.divId).find('.radio-ssex input[value='+(acc[val]?'1':'0')+']').prop('checked'));
                $("#" + load.divId).find('.radio-ssex input[value=' + (acc[val] ? '1' : '0') + ']').prop('checked', true);
                continue;
            }
            console.log($("#" + load.divId).find('input[name=' + val + ']'));
            console.log(val);
            $("#" + load.divId).find('input[name=' + val + ']').val(acc[val]);
        }

        layui.form.render();

        load.addEvent();

    }


    addEvent() {
        let load = this;
        load.addForm();
    }



    addForm() {


        let load = this;

        $("#id-studnet-body-peasonal-center-details-form").on("submit", function (e) {
            e.preventDefault();

            console.log("FORM");
            console.log(this);

           
            var formData = $(this).serializeArray();

            console.log(formData);

            // return 0;

            let studentJson = {};


          

            for (let i = 0; i < formData.length; i++) {
                studentJson[formData[i]['name']] = formData[i]['value'];
            }


            // console.log(studentJson);

            // return 0;



            $.ajax({
                type: "get",
                data: { 'student': JSON.stringify(studentJson) },
                url: "/Lock/Update/Acc/Stud",
                success: function (res) {

                    console.log(res);
                    console.log("add-stud");

                    if (res.statue == 0) {
                        // 添加成功后应该跳转
                        layer.msg(res.message, { icon: 6 });
                        layer.close(load.addLayerindex);

                    } else {
                        layer.msg(res.message, { icon: 5, time: 2000 });
                    }

                    // load.render();
                    layui.table.render(load.tableSetup);

                },

                error: function () {
                    console.log("超时");
                }

            });




        });//加载函数末

    }



}

